package com.chinathinks.sms.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.chinathinks.core.json.JsonHelper;
import com.chinathinks.core.metatype.Dto;
import com.chinathinks.core.mvc.xstruts.action.ActionForm;
import com.chinathinks.core.mvc.xstruts.action.ActionForward;
import com.chinathinks.core.mvc.xstruts.action.ActionMapping;
import com.chinathinks.core.util.G4Constants;
import com.chinathinks.core.web.BizAction;
import com.chinathinks.core.web.CommonActionForm;


/**
 * 
 * @author Dove
 *
 */
public class SmsBoxAction extends BizAction {

	
	public ActionForward inboxInit(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return mapping.findForward("inbox");
	}
	
	
	public ActionForward outboxInit(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return mapping.findForward("outbox");
	}
	
	public ActionForward tempboxInit(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return mapping.findForward("tempbox");
	}
	

	public ActionForward queryInbox(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		CommonActionForm aForm = (CommonActionForm) form;
		Dto dto = aForm.getParamAsDto(request);
		List list = g4Reader.queryForPage("SmsGroup.queryInbox", dto);
		Integer countInteger = (Integer) g4Reader.queryForObject("SmsGroup.countInbox", dto);
		String jsonString = JsonHelper.encodeList2PageJson(list, countInteger, G4Constants.FORMAT_Date);
		super.write(jsonString, response);
		return mapping.findForward(null);
	}

	
	
	public ActionForward queryOutbox(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		CommonActionForm aForm = (CommonActionForm) form;
		Dto dto = aForm.getParamAsDto(request);
		List list = g4Reader.queryForPage("SmsGroup.queryOutbox", dto);
		Integer countInteger = (Integer) g4Reader.queryForObject("SmsGroup.countOutbox", dto);
		String jsonString = JsonHelper.encodeList2PageJson(list, countInteger, G4Constants.FORMAT_Date);
		super.write(jsonString, response);
		return mapping.findForward(null);
	}
	
	public ActionForward queryTempbox(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		CommonActionForm aForm = (CommonActionForm) form;
		Dto dto = aForm.getParamAsDto(request);
		List list = g4Reader.queryForPage("SmsGroup.queryTempbox", dto);
		Integer countInteger = (Integer) g4Reader.queryForObject("SmsGroup.countTempbox", dto);
		String jsonString = JsonHelper.encodeList2PageJson(list, countInteger, G4Constants.FORMAT_Date);
		super.write(jsonString, response);
		return mapping.findForward(null);
	}
	
	
}
